<?php include "common/page_frame/header.html";?>
<?php include "common/page_frame/leftbar.html";?>
<div class="myRight">
<?

/* -------要显示的参数列表----第一部分---
 * $_GET['orderid'] 订单号
 * $UUstatus       订单状态
 * $UUdtime        验证时间
 * $UUordertime    下单时间
 * $UUbegin_to_end 有效期
 * $UUcoupon_id    优惠券id
 * $UUcoupon_name  优惠券名称
 * $UUcoupon_money 优惠金额
 * $UUpmode   支付方式
 * $UUmemo    备注
 * $UUcode    凭证码
 * $UUremsg   短信发送次数
 * UUgetaddr  取票地址
 * $UUname_tel   取票人(电话号码)
 * $UUseries_1   座位分区
 * $UUseries_2   座位号
 * UUpersonid    身份证
 * $UUmoney 订单实付金额
 * $UUaids_dname    分销链
 *
 *
 * 以下变量都是已订单号为键的数组
 * $UUreb   值为 '退票收费方式(固定/百分比)'+金额/百分比值
 * $UUtitle 值为订单的景区名+票类名称
 * $UUtnum  值为订单数量
 * $UUtnum_u 如果订单已验证 值为那么订单数量 否则 值为0
 * $UUprice 是最终显示出来的 用订单号为键 (字符串)"单价/单价/单价"为值的数组
 * */

$status = array(
    '<em style="color: #f07845">未使用</em>',
    '<em style="color: #3dba31">已使用</em>',
    '<em style="color: #92a0ab">已过期</em>',
    '<em style="color: #92a0ab">已取消</em>',
    '<em style="color: #92a0ab">凭证码被替代</em>',
    '<em style="color: #92a0ab">已撤改</em>',
    '<em style="color: #92a0ab">已撤销</em>',
    99=>'<em style="color: #f07845">未支付</em>',
);

$pmode = array(
    '账户余额',
    '支付宝',
    '授信支付',
    '自供自销',
    '现场支付',
    '微信支付',
    '',
    '银联支付',
    '环迅支付）'
);

//2845440 没有转分销的   2822274 有转分销的  2850630 有优惠券的  2852747(没转分销) 2843215	(有转分销) 联票主票  2854026 套票主票   2819903 有座位号的
//用户登录查看订单测试用 3385 是最开始的供应商 有转分销 非联票 2780619  26816 是最终购买者 有转分销 联票 2762443     56153 是最终购买者 无转分销 联票 2854147
if($_GET['orderid']+0==0) exit('订单号有误');
$soap = new SoapClient(null,array(
        "location" => "http://localhost/open/openService/pft_insideMX.php",
        "uri" => "www.16u.com?ac_16u=16ucom|pw_16u=c33367701511b4f6020ec61ded352059|auth_16u=true")
);
$xml = simplexml_load_string($soap->Order_Globle_Search( "","", "", "", "", "", "", "", "", "", "", "", (int)$_GET['orderid'], "", "", "", "", "", "", "", "0", "1", "0", "0","","0","","0","","", "","","","0","",""))->Rec;

if(!(int)$xml->UUordernum){
    exit('订单号有误');
}
//公共信息
$UUstatus = (int)$xml->UUpaystatus!=2 ? $status[(int)$xml->UUstatus]:$status[99];//未支付的情况下 状态显示为 '未支付' 其他情况 是什么状态就显示什么状态

$UUdtime        = str_replace('-','/',substr((string)$xml->UUdtime,0,16));
$UUordertime    = str_replace('-','/',substr((string)$xml->UUordertime,0,16));
$UUbegin_to_end = str_replace('-','/',substr((string)$xml->UUbegintime,0,10)).'至'. str_replace('-','/',substr((string)$xml->UUendtime,0,10));


$UUcode     = (string)$xml->UUcode;
$UUmemo     = (string)$xml->UUmemo!='0' ? (string)$xml->UUmemo : '无';
$UUremsg    = (string)$xml->UUremsg ? $xml->UUremsg:'非平台发送';
$UUgetaddr  = (string)$xml->UUgetaddr;
$UUname_tel = (string)$xml->UUordername.'('.(string)$xml->UUordertel.')';
$UUpersonid = (string)$xml->UUpersonid!=0?(string)$xml->UUpersonid:'游客没有填写身份证';

$ordernum[(int)$_GET['orderid']] = 1;//已处理过的订单标记 防止相同订单重复统计
$UUltitle[(int)$_GET['orderid']] = (string)$xml->UUltitle;
$UUttitle[(int)$_GET['orderid']] = (string)$xml->UUttitle;
$UUtnum  [(int)$_GET['orderid']] = (int)   $xml->UUtnum;
$UUtnum_u[(int)$_GET['orderid']] = (string)$xml->UUdtime != '0000-00-00 00:00:00'?(int)$xml->UUtnum : 0;//已验证数量
$UUstatus_child[(int)$_GET['orderid']] =  $status[(int)$xml->UUstatus];
$sql = "select reb,reb_type from uu_jq_ticket  where id={$xml->UUtid} limit 1";
$GLOBALS['le']->query($sql);
$row=$GLOBALS['le']->fetch_assoc();
if($row['reb_type'] == 0){
    $UUreb[(int)$_GET['orderid']]['show'] = '售价百分比'.$row['reb'].'%';
}elseif($row['reb_type'] == 1){
    $UUreb[(int)$_GET['orderid']]['show'] = '固定金额'.($row['reb']/100).'元';
}
$UUreb[(int)$_GET['orderid']]['reb_type'] = $row['reb_type'];
$UUreb[(int)$_GET['orderid']]['reb'] = $row['reb'];

//取座位号
$UUseries = unserialize((string)$xml->UUseries);
$UUseries_1 = $UUseries_2 = '无';
if(is_array($UUseries)){
    $UUseries_1 = explode('，',$UUseries[6]);
    $UUseries_1 = explode('：',$UUseries_1[1]); $UUseries_1 = $UUseries_1[1];
    $UUseries_2 = explode('：',$UUseries[6]); $UUseries_2 = $UUseries_2[3];
}

//线路产品的集合地点
$UUass_station = '无';
if((string)$xml->UUp_type=='B'){
    $sql = "select ass_station from uu_land_f where tid={$xml->UUtid} limit 1";
    $GLOBALS['le']->query($sql);
    $GLOBALS['le']->fetch_assoc();
    $UUass_station = $GLOBALS['le']->f('ass_station');
    $UUass_station = unserialize($UUass_station);
    $UUass_station = $UUass_station[(string)$xml->UUassembly];
}

//优惠券
$UUcoupon_money = 0;$UUcoupon_name = $UUcoupon_id ='无';
if((int)$xml->UUonsale==1 &&($_SESSION['sid ']==(int)$xml->UUaid || $_SESSION['sid ']==(int)$xml->UUmid || $_SESSION['sid']==1)){
    $sql = "select f.id,eMoney,coupon_name from pft_onsale_record r
            left join pft_member_coupon d on r.ordernum=d.ordernum
            left join pft_coupons f on d.coupon_id=f.id
            where r.ordernum='{$_GET['orderid']}' limit 1";
    $GLOBALS['le']->query($sql);
    if($row= $GLOBALS['le']->fetch_assoc()){
        $UUcoupon_id = $row['id'];
        $UUcoupon_name = $row['coupon_name'];
        $UUcoupon_money = $row['eMoney']/100;
    }
}
//如果订单是联票的主票
$xml_concat = new stdClass();
$xml_concat->Rec= array();
if((int)$xml->UUconcat_id==(int)$_GET['orderid']){
    $xml_concat = simplexml_load_string($soap->Order_Globle_Search( "","", "", "", "", "", '', '', "", "", "", "", (int)$_GET['orderid'], "", "", "", "", "", "", "", "0", "30", "0", "0","","0","","0","","", "","1","","0","",""));
    foreach($xml_concat as $v){
        if($UUreb[(int)$v->UUordernum]) continue;
        $UUltitle[(int)$v->UUordernum] = (string)$v->UUltitle;
        $UUttitle[(int)$v->UUordernum] = (string)$v->UUttitle;
        $UUtnum  [(int)$v->UUordernum] = (int)$v->UUtnum;
        $UUtnum_u[(int)$v->UUordernum] = (string)$v->UUdtime != '0000-00-00 00:00:00'?(int)$v->UUtnum : 0;//已验证数量
        $UUstatus_child[(int)$v->UUordernum] =  $status[(int)$v->UUstatus];
        $sql = "select reb,reb_type from uu_jq_ticket  where id={$v->UUtid} limit 1";
        $GLOBALS['le']->query($sql);
        $row=$GLOBALS['le']->fetch_assoc();
        if($row['reb_type'] == 0){
            $UUreb[(int)$v->UUordernum]['show'] = '售价百分比'.$row['reb'].'%';
        }elseif($row['reb_type'] == 1){
            $UUreb[(int)$v->UUordernum]['show'] = '固定金额'.($row['reb']/100).'元';
        }
        $UUreb[(int)$v->UUordernum]['reb_type'] = $row['reb_type'];
        $UUreb[(int)$v->UUordernum]['reb'] = $row['reb'];
    }
}

//支付方式 分销链 支付价格 根据是否管理员来区分来取
if($_SESSION['sid']==1){//管理员
    if((string)$xml->UUaids){//有转分销
        //供销商名字
        $UUaids = (string)$xml->UUaids.','.(string)$xml->UUmid;
        $dnames = dnames($UUaids);
        $UUaids = explode(',',$UUaids);
        foreach($UUaids as $v){
            $UUaids_dname.= $dnames[$v].'/';
        }
        $UUaids_dname = rtrim($UUaids_dname,'/');
        //支付方式-+
        $count_aids = count($UUaids)-1;
        $aids_money = unserialize((string)$xml->UUaids_money);
        foreach($aids_money as $k=>$v){
            if($k==$count_aids) break;
            $UUpmode .= $v[1]==1?$pmode[0]:$pmode[2];
            $UUpmode .= '/';
        }
        $UUpmode .= $pmode[(int)$xml->UUpmode];
        //价钱
        $price_tmp = (string)$xml->UUaids_price.','.(string)$xml->UUtprice;
        $price[(int)$_GET['orderid']]  = explode(',',$price_tmp);
        if(count($xml_concat->Rec)>0){
            foreach($xml_concat->Rec as $v){
                if($ordernum[(int)$v->UUordernum]) continue;
                $ordernum[(int)$v->UUordernum]=1;
                $price_tmp = (string)$v->UUaids_price.','.(string)$v->UUtprice;//$price_tmp 是临时变量 用来存逗号隔开的价钱
                $price[(int)$v->UUordernum] = explode(',',$price_tmp);//$price = array('订单号'=>array(价钱1/价钱2/价钱3))
            }
        }
        foreach($price as$k=> $va){
            foreach($va as $val)
                $UUprice[$k] .= '&yen'.($val/100).'/';
        }
        foreach($UUprice as$k=> $v){
            $UUprice[$k] = rtrim($v,'/');
        }

        //总价钱
        foreach($price as$key => $v){
            foreach($v as$k   => $val){
                $money[$k] += $val/100*$UUtnum[$key];
            }
        }
        $money[$k] = $money[$k]-$UUcoupon_money;
        foreach($money as $v){
            $UUmoney .= '&yen;'.$v.'/';
        }
        $UUmoney = rtrim($UUmoney,'/');

    }else{//没转分销的情况
        //供销商名字
        $UUaids .= (string)$xml->UUaid.','.(string)$xml->UUmid;
        $dnames = dnames($UUaids);
        $UUaids = explode(',',$UUaids);
        if(count($UUaids)==2) //自供自销的话 只显示一个名字
            $UUaids = array_unique($UUaids);
        foreach($UUaids as $v){
            $UUaids_dname.= $dnames[$v].'/';
        }
        $UUaids_dname = rtrim($UUaids_dname,'/');
        //支付方式-+
        $UUpmode .= $pmode[(int)$xml->UUpmode];
        //价钱
        $UUprice[(int)$_GET['orderid']] .= '&yen'.((int)$xml->UUtprice/100);
        $price[(int)$_GET['orderid']] = (int)$xml->UUtprice;//$price = array('订单号'=>价钱)
        if(count($xml_concat->Rec)>0){
            foreach($xml_concat->Rec as $v){
                if($ordernum[(int)$v->UUordernum]) continue;
                $ordernum[(int)$v->UUordernum]=1;
                $price[(int)$v->UUordernum] = (int)$v->UUtprice;
            }
            foreach($price as$k=> $va){
                if((int)$k==(int)$xml->UUordernum) continue;
                $UUprice[$k] = '&yen'.($va/100);
            }
        }
        //总价钱
        foreach($price as$key => $v){
                $money += $v/100*$UUtnum[$key];
        }

        $money = $money-$UUcoupon_money;
        $UUmoney = '&yen'.$money;
    }
}else{//普通用户
    if((string)$xml->UUaids){//有转分销
        //供销商名字
        $UUaids = (string)$xml->UUaids.','.(string)$xml->UUmid;
        $dnames = dnames($UUaids);
        $UUaids = explode(',',$UUaids);
        //判断用户是否在分销链里 是否有权限查看这个订单
        if(!in_array($_SESSION['sid'],$UUaids)) exit('您无此订单的查看权限');
        $position = array_search($_SESSION['sid'],$UUaids);
        if($position!=0){//判断是否有再次购买的按钮 并且取出上级aid的值
            $buy_more = 1;
            $buy_more_aid = $UUaids[$position-1];
        }
        $count_aids = count($UUaids)-1;
        //和上面的管理员不同 价钱和分销链一起取 因为要判断权限
        $price_tmp = (string)$xml->UUaids_price.','.(string)$xml->UUtprice;
        $price[(int)$_GET['orderid']]  = explode(',',$price_tmp);
        //联票的子票处理
        if(count($xml_concat->Rec)>0){
            foreach($xml_concat->Rec as $v){
                if($ordernum[(int)$v->UUordernum]) continue;
                $ordernum[(int)$v->UUordernum]=1;
                $price_tmp = (string)$v->UUaids_price.','.(string)$v->UUtprice;//$price_tmp 是临时变量 用来存逗号隔开的价钱
                $price[(int)$v->UUordernum] = explode(',',$price_tmp);//$price = array('订单号'=>array(价钱1/价钱2/价钱3))
            }
        }

        foreach($UUaids as $k => $v){//只保留该用户在分销链中的前中后三个位置的用户 价钱也去掉
            if($k!=$position-1 && $k!=$position && $k!=$position+1){
                unset($UUaids[$k]);
                foreach($price as $key => $v){
                    unset($price[$key][$k]);
                }
                continue;
            }
            if($k==$position-1 && $_SESSION['sid']!=reset($UUaids)){//如果不是最初供应商 那么都取一下自己支付给上一级的钱
                foreach($price as $key => $va){
                    $UUprice[$key] .= '&yen'.($price[$key][$k]/100).'/';
                }
            }
            if($k==$position && $_SESSION['sid']!=(string)$xml->UUmid){//如果不是最终购买者 那么都取下一级支付给自己的钱
                foreach($price as $key => $va){
                    $UUprice[$key] .= '&yen'.($price[$key][$k]/100).'/';
                }
            }
        }
        foreach($UUaids as $v){
            $UUaids_dname.= $dnames[$v].'/';
        }
        $UUaids_dname = rtrim($UUaids_dname,'/');
        //支付方式
        $aids_money = unserialize((string)$xml->UUaids_money);
        foreach($aids_money as $k=>$v){
            if($k==$count_aids) break;
            if(in_array($v[0],$UUaids) && $v[0]!=reset($UUaids)){
                $UUpmode .= $v[1]==1?$pmode[0]:$pmode[2];
                $UUpmode .= '/';
            }
        }
        if($_SESSION['sid']==(string)$xml->UUaid || $_SESSION['sid']==(string)$xml->UUmid){
            $UUpmode .= $pmode[(int)$xml->UUpmode];
        }
        $UUpmode = rtrim($UUpmode,'/');
        foreach($UUprice as $k => $v){
            $UUprice[$k] = rtrim($v,'/');
        }
        //总价钱
        foreach($price as $key => $v){
            foreach($v as $k   =>$val){
                $money[$k] += $val/100*$UUtnum[$key];
            }
        }
        $money[$k] = $money[$k]-$UUcoupon_money;
        foreach($money as $v){
            $UUmoney .= '&yen'.$v.'/';
        }
        $UUmoney = rtrim($UUmoney,'/');
    }else{//没转分销
        $UUaids = (string)$xml->UUaid.','.(string)$xml->UUmid;
        $dnames = dnames($UUaids);
        $UUaids = explode(',',$UUaids);
        if($_SESSION['sid']!=(string)$xml->UUaid){//判断是否有再次购买的按钮 并且取出上级aid的值
            $buy_more = 1;
            $buy_more_aid = (string)$xml->UUaid;
        }
        if(!in_array($_SESSION['sid'],$UUaids)) exit('您无此订单的查看权限');
        if(count($UUaids)==2) //自供自销的话 只显示一个名字
            $UUaids = array_unique($UUaids);
        foreach($UUaids as $v){
            $UUaids_dname.= $dnames[$v].'/';
        }
        $UUaids_dname = rtrim($UUaids_dname,'/');
        $UUprice[(int)$_GET['orderid']] .= '&yen'.((int)$xml->UUtprice/100);
        $price[(int)$_GET['orderid']] = (int)$xml->UUtprice;
        $UUpmode = $pmode[(int)$xml->UUpmode];
        if(count($xml_concat->Rec)>0){
            foreach($xml_concat->Rec as $v){
                if($ordernum[(int)$v->UUordernum]) continue;
                $ordernum[(int)$v->UUordernum]=1;
                $price[(int)$v->UUordernum] = (string)$v->UUtprice;
            }
            foreach($price as$k=> $va){
                if((int)$k==(int)$xml->UUordernum) continue;
                $UUprice[$k] = '&yen'.($va/100);
            }
        }
        //总价钱
        foreach($price as $key => $v){
            $money += $v/100*$UUtnum[$key];
        }

        $money = $money-$UUcoupon_money;
        $UUmoney = '&yen'.$money;
    }
}

switch((int)$xml->UUordermode){
    case '1':
        $UUpmode .= "<em style='color:fuchsia'>（散客预订）</em>";
        break;
    case '9':
        $UUpmode .= "<em style='color:fuchsia'>（现场购票）</em>";
        break;
    case '10':
        $UUpmode .= "<em style='color:fuchsia'>（云票务购票）</em>";
        break;
}

//查询订单的退票修改记录  不查询套票的子票修改情况 所以把套票的查询放在下面一步
$ordernum_str = implode(',',array_keys($ordernum));
$sql = "select orderid,pre_num,done_num,rectime from pft_order_num_modify where orderid in ($ordernum_str)";
$GLOBALS['le']->query($sql);
while($row=$GLOBALS['le']->fetch_assoc()){
    if($row['rectime']>(string)$xml->UUdtime && (string)$xml->UUdtime!='0000-00-00 00:00:00'){
        $row['status'] = $status[5];//验证后 '被撤改'
    }elseif($row['rectime']==(string)$xml->UUctime && $row['done_num']==0){
        $row['status'] = $status[3];//取消
    }elseif($row['rectime']==(string)$xml->UUdtime){
        $row['status'] = $status[1];//和验证验证时间相等 已使用
    }elseif(((string)$xml->UUdtime=='0000-00-00 00:00:00' && (string)$xml->UUctime=='0000-00-00 00:00:00')|| $row['rectime']<(string)$xml->UUdtime){
        $row['status'] = $status[0];//在验证时间之前 未使用
    }
    switch ($UUreb[$row['orderid']]['reb_type']) {
    	case '1':
    		$row['reb'] = ($row['pre_num']-$row['done_num'])*$UUreb[$row['orderid']]['reb']/100;
    		break;
        case '0':
            if(is_array($price[$row['orderid']]))
                $row['reb'] = ($row['pre_num']-$row['done_num'])*($UUreb[$row['orderid']]['reb']/100*end($price[$row['orderid']]))/100;
            else
                $row['reb'] = ($row['pre_num']-$row['done_num'])*($UUreb[$row['orderid']]['reb']/100*$price[$row['orderid']])/100;
            break;
    }
    $row['rectime'] = str_replace('-','/',$row['rectime']);
    $UUmodify[$row['orderid']] = $row;
}


//如过是套票 那么查询子票信息
if((int)$xml->UUpack_order==1){
   //$UUtitle [(int)$_GET['orderid']] .= '（套票主票）';
    $xml_pack = simplexml_load_string($soap->Order_Globle_Search( "","", "", "", "", "", "", "", "", "", "", "", (int)$_GET['orderid'], "", "", "", "", "", "", "", "0", "30", "0", "0","","0","","0","","", "","","2","0","",""));
    foreach($xml_pack as $v){
        if($ordernum[(int)$v->UUordernum]) continue;
        $ordernum[(int)$v->UUordernum]=1;
        $UUltitle [(int)$v->UUordernum] = (string)$v->UUltitle;
        $UUttitle [(int)$v->UUordernum] = (string)$v->UUttitle;
        $UUtnum  [(int)$v->UUordernum] = (int)$v->UUtnum;
        $UUtnum_u[(int)$v->UUordernum] = (string)$v->UUdtime != '0000-00-00 00:00:00'?(int)$v->UUtnum.'（'.substr((string)$v->UUdtime,0,16).'）' : 0;//已验证数量
        $UUprice [(int)$v->UUordernum] = $_SESSION['sid']==1?'&yen'.(int)$v->UUtprice/100:'-';//非管理员子票价钱不可见
        $UUstatus_child[(int)$v->UUordernum] = $status[(int)$v->UUstatus];
        $sql = "select reb,reb_type from uu_jq_ticket  where id={$v->UUtid} limit 1";
        $GLOBALS['le']->query($sql);
        $row=$GLOBALS['le']->fetch_assoc();
        if($row['reb_type'] == 0){
            $UUreb[(int)$v->UUordernum]['show'] = '售价百分比'.($row['reb']).'%';
        }elseif($row['reb_type'] == 1){
            $UUreb[(int)$v->UUordernum]['show'] = '固定金额'.($row['reb']/100).'元';
        }
    }
}

function dnames($dnames){
    $sql = "select id,dname from pft_member where id in ($dnames)";
    $GLOBALS['le']->query($sql);
    while($row=$GLOBALS['le']->fetch_assoc()){
        $return[$row['id']] = $row['dname'];
    }
    return $return;
}

?>
<?php include "tpl/new_yl/orderDetail/index.html";?>
</div>
<?php include "common/page_frame/footer.html";?>
